app = {
    ajax: function (url, data, success, fail, dataType = 'json') {
        jQuery.ajax({
            url: url,
            data: data,
            type: (data === null || data === undefined) ? 'get' : 'post',
            cache: false,
            dataType: dataType,
            success: function (data) {
				if (typeof (success) === 'function') {
                    success(data)
                }
            },
            error: function (data) {
                if (typeof (fail) === 'function') {
                    fail(data)
                } else {
					layer.msg('网络链接错误', {icon: 2,time: 1000});
                }
            }
        })
    },
    postData: function (url, parameter, callback, callerror, ajaxType, ajaxTime) {
        ajaxType = ajaxType || "POST";
        ajaxTime = ajaxTime || 60000;
        $.ajax({
            type: ajaxType,
            url: url,
            async: true,
            dataType: 'html',
            timeout: ajaxTime,
            data: parameter,
            success: function (data) {
                if (callback == null) {
                    $("#ajaxshow").html(data);
                    return false;
                } else {
                    callback(data);
                }
            },
            error: function (error) {
                layer.close();
                if (callerror == null) {
                    layer.msg('网络链接错误', {icon: 2,time: 1000});
                } else {
                    callerror(error);
                }
            }
        });
    },
    msg: function (msg, time = 2) {
        layer.open({
            content: msg
            , skin: 'msg'
            , time: time
        });
    },
    mode: function (url, bt, se) {
        se ? '' : $("#modal").click();
        var bt = bt || '信息文本';
        var url = url;
        get_url(url, bt);
    },
    gethtml: function (url, seid, lod, cz) {
        seid = seid || 'main-container';
        app.ajax(url, null, function (d) {
			Codebase.blocks('#'+ seid, 'state_toggle');
            $("#" + seid).html(d);
            return false
        }, '', '', 'html');
    },
    is_PayType: function (type) {
        var name;
        switch (type) {
            case 0:
                name = 'ypay';
                break;
            case 1:
                name = 'alipay';
                break;
            case 2:
                name = 'qqpay';
                break;
            case 3:
                name = 'wxpay';
                break;
        }
        return name;
    }
};

/*** 模态窗口调用 ***/
function get_url(url, bt) {
    $("#biaoti").html(bt);
    $("#showInfo").html("<div class='block block-mode-loading'></div>");
    app.postData(
        url, '', function (d) {
            $("#showInfo").html(d);
            return false
        }, function (d) {
            $("#showInfo").html("<p style='text-align: center;margin:20px auto;'><b>加载失败，请稍后重试！</b></p>")
            return false
        }, 'GET'
    );
}

function get_ajax_modal(data, bt) {
    $("#modal").click();
    $("#biaoti").html(bt);
     Codebase.loader('show');
    $("#showInfo").html(data);
    return false;
}
